﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Xml;

namespace Fulcrum
{
    static public class XmlReaderHelp
    {
        public static bool GetOptionalBoolAttributeValue(XmlReader xmlReader, string attributeName, bool defaultValue)
        {
            bool attributeValue;

            string attributeValueString = GetOptionalAttributeValue(xmlReader, attributeName, defaultValue.ToString());

            if (String.Equals(attributeValueString, "False", StringComparison.InvariantCultureIgnoreCase))
            {
                attributeValue = false;
            }
            else
            {
                attributeValue = true;
            }

            return attributeValue;
        }

        public static string GetOptionalAttributeValue(XmlReader xmlReader, string attributeName, string defaultValue)
        {
            string attributeValue = xmlReader.GetAttribute(attributeName);

            if (attributeValue == null)
            {
                attributeValue = defaultValue;
            }

            return attributeValue;
        }

    }
}
